$(document).ready(function(){
	var date=new Date();
	var orderDate=date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
	$.ajax({
		url:'dishOrder_searchDataListByDate.action',
		dataType:'json',
		type:'POST',
		data:{
			'orderDate':orderDate,
		},
		success:function(data){
			if (data.status == "200"){
				for(var i=0,j=1;i<data.data.length;i++,j++){
					var value=data.data[i];
				$('#order-list3').after(" <li class='list-group-item'>"+
					"<table style='width: 100%;'>"+
						"<tr class='first-title'>"+
							"<td>"+j+"</td>"+
							"<td>"+value.diningTableName+"</td>"+
							"<td>流水号:"+value.serialsNumber+"</td>"+
							"<td>开台时间:"+value.creatTime+"</td>"+
							"<td>￥"+value.price+"</td>"+
							"<td><button class='btn btn-warning'>结账</button></td><td><span class='glyphicon expand glyphicon-chevron-left'></span></td></tr></table></li>");
				}
			} else {
//				window.location.href = "error.html";
			}
		}
	}).done(function(){
		var flag=true;
		$('.expand').unbind('click').on('click',function(){	
			var Number=$(this).parents('.first-title').children().eq(2).text();
//			alert($(this).parents('.notPay').find('.first-title').attr('class'));
			var serialsNumber=Number.substr(4,Number.length-4);
			var class_name=$(this).attr("class");
			if($('#'+serialsNumber).attr("data-flag")){
				$.ajax({
					url:'dishOrderItem_searchDataListBySerialsNumber.action',
					dataType:'json',
					type:'POST',
					data:{
						'serialsNumber':serialsNumber
					},
					success:function(data){
						$('#'+serialsNumber).nextAll().remove();
						for(var i=0;i<data.data.length;i++){
							var value=data.data[i];
							$('#'+serialsNumber).after("<tr class='chashier-order-detail' >"+
								"<td></td>"+
								"<td>"+value.dishName+"</td>"+
								"<td>X"+value.dishNum+"</td>"+
								"<td>￥"+value.price+"</td>"+
								"<td>"+value.enumName+"</td><td><a href='#' class='btn btn-warning'>上菜</a></td><td><a href='#' class='btn btn-danger'>退菜</a></td></tr>");
						}
						$('#'+serialsNumber).nextAll().show();
						$('#'+serialsNumber).attr({'data-flag':null});
					}
				}).done(function(){
					//expand();
				});
			}else{
				$('#'+serialsNumber).nextAll().hide();
				$('#'+serialsNumber).attr({'data-flag':true});
			}
			
		});

	});
});